#pragma once

#include <iostream>
#include <string>
#include <unistd.h>
#include <functional>
#include <vector>
#include <unordered_map>

using namespace std;

typedef std::function<void()> func;
vector<func> callbacks;
unordered_map<int, string> desc;

void readMySQL()
{
    cout << "process[" << getpid() << "] 执行访问数据库的任务\n" << endl;
}

void execuleUrl()
{
    cout << "process[" << getpid() << "] 执行URL解析\n" << endl;
}

void cal()
{
    cout << "process[" << getpid() << "] 执行加密任务\n" << endl;
}

void save()
{
    cout << "process[" << getpid() << "] 执行数据持久化任务\n" << endl;
}

void load()
{
    desc.insert({callbacks.size(), "readMySQL: 执行数据库访问"});
    callbacks.push_back(readMySQL);

    desc.insert({callbacks.size(), "execuleUrl: 执行URL解析"});
    callbacks.push_back(execuleUrl);

    desc.insert({callbacks.size(), "cal: 执行数据加密"});
    callbacks.push_back(cal);

    desc.insert({callbacks.size(), "save: 执行数据的文件保存"});
    callbacks.push_back(save);
}

void showHandler()
{
    for (const auto &iter : desc)
    {
        cout << iter.first << "\t" << iter.second << endl;
    }
}

int handlerSize()
{
    return callbacks.size();
}